﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class Group
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            pg.Type = "Group";
            pg.Title = "学生组";
            pg.AddText = "学生组增加";
            pg.EditText = "学生组修改";
            pg.LocateText = "学生组查询";
            pg.SMenuId = "JX01";
            pg.FileUrl = "../Schedule/Group";
            pg.Condition = "";
            pg.TableName = "cu_Cus_Group";
            pg.KeyFieldName = "id";
            pg.PopEditHeight = 290;
            pg.PopEditWidth = 360;
            HttpSessionState session = System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);
            pg.Sop = BasePage.Grant(session, pg.SMenuId);
            DataRow drUser = BasePage.GetUser(session);
            String leagueId = Fun.cString(drUser["LeagueId"]);

            String guid = "";
            String courseId = "0";
            String act = "";
            HttpRequest request = System.Web.HttpContext.Current.Request;
            if (request["guid"] != null) guid = Fun.cSql(request["guid"]);
            if (request["courseId"] != null) courseId = Fun.cSql(request["courseId"]);


            String button = "<a href =\"javascript:ShowModalUrl('popEdit', '../ManagerLay?type=GroupStudent&gId=[id]&keyCode='+GetKeyCode([id]), '添加学员', '', 0, 0)\" class='layui-btn layui-btn-primary layui-btn-xs'>添加学员</a>" +
                 "<a href=\"javascript: $.ajax({type: 'POST',url: '../Schedule/Course/AddToCourse'," +
                 "data: { id:[id],keyCode: GetKeyCode('[id]'),guid:'" + guid + "',courseId:'" + courseId + "'},dataType: 'json'," +
                 "success: function(data) {if (data.code == '0000') layui.layer.msg(data.message, {time: 500}, function() {parent.ShowStudent();});else layui.layer.msg(data.message);}})\"  class='layui-btn layui-btn-xs'>加入课程</a>";

            pg.Sql = @"select * from ( 
                       select t1.*,t2.num,'' link from cu_Cus_Group t1
                        left join (select groupId,count(*) num from cu_cus_group_detail group by groupId) t2 on t1.id=t2.groupId
                    ) cu_Cus_Group where leagueId= " + leagueId;
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.FieldName = "name"; cl.HeadText = "学员组"; cl.IsCheck = true; cl.Length = 50; cl.IsNull = false; cl.ErrMessage = cl.HeadText + ":必填且长度不能超过" + cl.Length; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "code"; cl.HeadText = "组标识"; cl.IsCheck = true; cl.Length = 10; cl.IsNull = false; cl.ErrMessage = cl.HeadText + ":必填且长度不能超过" + cl.Length; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "num"; cl.HeadText = "学员数"; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; cl.Script = button; pg.AddColumn(cl);
            return pg;
        }
    }
}